package cn.com.thingo.shyintelligent.ui.activity;

import android.content.Intent;
import android.graphics.Typeface;
import android.graphics.drawable.AnimationDrawable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.com.thingo.shyintelligent.R;
import cn.com.thingo.shyintelligent.base.BaseActivity;
import cn.com.thingo.shyintelligent.base.contract.EzWifiFirstStepContract;
import cn.com.thingo.shyintelligent.presenter.EzWifiFirstStepPresenter;
import cn.com.thingo.shyintelligent.widget.BoldSpan;


public class EzWifiFirstStepActivity extends BaseActivity<EzWifiFirstStepPresenter> implements EzWifiFirstStepContract.View, View.OnClickListener {
    @BindView(R.id.toolbar_left)
    ImageView ivLeft;
    @BindView(R.id.toolbar_title)
    TextView tvTitle;
    /**
     * 下一步按钮
     */
    @BindView(R.id.btnNext)
     Button btnNext;
    /**
     * 设备类型model
     */
    String deviceType;
    /**
     * 头顶示意文字
     */
    @BindView(R.id.topTip)
     TextView topTip;
    /**
     * 帮助按钮
     */
    @BindView(R.id.btnIntroduce)
     Button btnIntroduce;
    /**
     * 灯光闪烁背景
     */
    @BindView(R.id.imageBg)
    ImageView imageBg;
    /**
     * 灯光闪烁动画
     */
     AnimationDrawable aminBg;

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_ezwifi_first_step;
    }

    @Override
    protected void initEventAndData()   {
        initTitleBar();
        initUI();
    }

    private void initTitleBar() {
        ivLeft.setImageResource(R.mipmap.back);
        tvTitle.setText(R.string.auto_wifi_step_one_title);
    }
    private void initUI(){
        btnNext.setOnClickListener(this);
        btnIntroduce.setOnClickListener(this);

        SpannableString spanStr = new SpannableString(getString(R.string.tip_heard_voice));
        spanStr.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.auto_wifi_tip_red)), 12, 14,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanStr.setSpan(new BoldSpan(Typeface.NORMAL), 12, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        topTip.setText(spanStr);
        imageBg.setImageResource(R.mipmap.video_camera1_3);
        btnNext.setText(R.string.autowifi_heard_voice);
        btnIntroduce.setText(R.string.autowifi_not_heard_voice);
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.btnNext:
                intent = new Intent(this, EzWifiNetConfigActivity.class);
                intent.putExtras(getIntent());
                startActivity(intent);
                break;
            case R.id.btnIntroduce:
                intent = new Intent(this, EzWifiResetActivity.class);
                intent.putExtras(getIntent());
                startActivity(intent);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        if (aminBg != null) {
            aminBg.stop();
            aminBg = null;
        }
        super.onDestroy();
    }


    @OnClick({R.id.toolbar_left})
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.toolbar_left:
                finish();
                break;
        }
    }
}
